package com.it.shiro.utils;


import com.fasterxml.jackson.annotation.JsonInclude;
import com.it.shiro.enums.ErrorCodes;
import lombok.Data;
import org.apache.log4j.spi.ErrorCode;

/**
 * ClassName:ResultVO
 * Package:com.bjpowernode.validator.vo
 * Description: 描述信息
 *
 * @date:2022/3/19 11:12
 * @author:动力节点
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL) //非空的参数才会序列化
public class ResultVO {

    /**
     * 后端是否处理成功发
     */
    private Boolean success;
    /**
     * 错误码
     */
    private String code;
    /**
     * 错误消息
     */
    private String msg;
    /**
     * 给前端的返回值
     */
    private Object data;

    public static ResultVO success(){

        ResultVO resultVO = new ResultVO();
        resultVO.setSuccess(true);
        return resultVO;
    }
     public static ResultVO success(Object data){
        ResultVO resultVO = new ResultVO();
        resultVO.setSuccess(true);
        resultVO.setData(data);
        return resultVO;
     }

    public static ResultVO error(ErrorCodes errorCode, Object data){
        ResultVO resultVO = new ResultVO();
        resultVO.setSuccess(false);
        resultVO.setCode(errorCode.getCode());
        resultVO.setMsg(errorCode.getMsg());
        resultVO.setData(data);
        return resultVO;
    }
    public static ResultVO error(ErrorCodes errorCode){
        ResultVO resultVO = new ResultVO();
        resultVO.setSuccess(false);
        resultVO.setCode(errorCode.getCode());
        resultVO.setMsg(errorCode.getMsg());
        return resultVO;
    }


}
